<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/3/24
  Time: 11:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <form >
        <input type="text" name="name" id="nameId"/><span id="spanNameId"></span><br/>
        <input type="password" name="password"/><span id="spanPasswordId"></span><br/>
        <input type="submit" value="注册"/>
    </form>

    <script>
        $(function() {
            $('#nameId').blur(function() {
                $.post(
                    '<%=request.getContextPath()%>/ajax2',
                    {'name': $(this).val()},
                    function(jsonObj) {
                        console.log(jsonObj);
                        //{exist: true, msg: '此用户已经存在请更换一个'}
                        if (jsonObj.exist) {
                            $('#spanNameId').html(jsonObj.msg);
                            $('#spanNameId').css('color', 'red');
                        } else {
                            $('#spanNameId').html(jsonObj.msg);
                            $('#spanNameId').css('color', 'green');
                        }
                    },
                    'json'
                );
            })
        });



    </script>
</body>
</html>
